<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org">
<head th:include="_meta :: header">
<title>添加管理员 - 管理员管理 </title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" action="#" th:action="@{/user/add-user}" >
	<input type="hidden" name="save" value="true"/>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<input type="text" class="input-text" value="" placeholder="" id="username" name="username"/>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password"/>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<input type="password" class="input-text" autocomplete="off"  placeholder="确认新密码" id="password2" name="password2"/>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性别：</label>
		<div class="formControls col-xs-7 col-sm-8 skin-minimal">
			<div class="radio-box">
				<input type="radio" id="sex-1" name="sexType" value="1" checked="checked"/>
				<label for="sex-1" >男</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="sex-0" name="sexType" value="0" />
				<label for="sex-0" >女</label>
			</div>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否启用：</label>
		<div class="formControls col-xs-7 col-sm-8 skin-minimal">
			<div class="radio-box">
				<input type="radio" id="qd"  name="available" value="1" />
				<label for="qd">启用</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="nqd" name="available" value="0" checked="checked"/>
				<label for="nqd">不启用</label>
			</div>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">手机：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<input type="text" class="input-text" value="" placeholder="" name="tel" id="tel" />
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">邮箱：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<input type="text" class="input-text" placeholder="@" name="email" id="email"/>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">角色：</label>
		<div class="formControls col-xs-7 col-sm-8">
			<span  th:each="role : ${roleList}">
				<label >
					<input type="checkbox" th:value="${role.id}" value="" name="userRoles" />
					<span th:text="${role.name}"></span>
				</label>
			</span>
			</div>
		</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" id="subbtn" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
		</div> 
	</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去--> 
<div th:replace="_footer :: footerjs"></div>
 <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/jquery.validate.js}" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/validate-methods.js}" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/messages_zh.js}"  src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			username:{
				required:true,
				minlength:4,
				maxlength:16
			},
			password:{
				required:true,
			},
			password2:{
				required:true,
				equalTo: "#password"
			},
			sexType:{
				required:true,
			},
			tel:{
				isPhone:true,
			},
			email:{
				email:true,
			},
		},
		onkeyup:false,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "/user/add-user" ,
				success: function(data){
					if(data == 1){
						//禁止重复提交
						$('#subbtn').attr("type","button");
						layer.msg('添加成功!',{icon:1,time:1000},function(){
							var index = parent.layer.getFrameIndex(window.name);
							parent.location.reload();
							parent.layer.close(index);
						});
					}else if(data == 2){
						layer.msg("用户已存在");
						return false;
					}else{
						layer.msg('增加失败!',{icon:1,time:1000});
					}
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:1,time:1000});
				}
			});
		
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>